package java09;

public class FizzBuzz {
    private int num;
    private int i=1;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public FizzBuzz(int num) {
        super();
        this.num = num;
    }

    public void fizz() {
        while(i<=num){
            synchronized (FizzBuzz.class) {
                if(i%3==0 && i%5!=0){
                    System.out.print("fizz ");
                    i++;
                }else{
                    FizzBuzz.class.notifyAll();
                    try {
                        FizzBuzz.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public void buzz() {
        while(i<=num){
            synchronized (FizzBuzz.class) {
                if(i%3!=0 && i%5==0){
                    System.out.print("buzz ");
                    i++;
                }else{
                    FizzBuzz.class.notifyAll();
                    try {
                        FizzBuzz.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public void fizzbuzz() {
        while(i<=num){
            synchronized (FizzBuzz.class) {
                if(i%3==0 && i%5==0){
                    System.out.print("fizzbuzz ");
                    i++;
                }else{
                    FizzBuzz.class.notifyAll();
                    try {
                        FizzBuzz.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public void number() {
        while(i<=num){
            synchronized (FizzBuzz.class) {
                if(i%3!=0 && i%5!=0){
                    System.out.print(i+" ");
                    i++;
                }else{
                    FizzBuzz.class.notifyAll();
                    try {
                        FizzBuzz.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
